package top.littlejiang.onlinexam.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import top.littlejiang.onlinexam.common.base.BaseServiceImpl;
import top.littlejiang.onlinexam.entity.OlexamUserCourse;
import top.littlejiang.onlinexam.mapper.OlexamUserCourseMapper;
import top.littlejiang.onlinexam.service.OlexamUserCourseService;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 用户（学生）课程表 服务实现类
 * </p>
 *
 * @author chen
 * @since 2021-03-11
 */
@Service
public class OlexamUserCourseServiceImpl extends BaseServiceImpl<OlexamUserCourseMapper, OlexamUserCourse> implements OlexamUserCourseService {

    /**
     * 根据用户id 查询课程
     *
     * @param userId
     * @param courseName
     * @return
     */
    @Override
    public List<Serializable> selectIdsByUser(Integer userId, String courseName) {
        List<Integer> list = this.baseMapper.selectIdsByUser(userId, courseName);
        List<Serializable> rst = new ArrayList<>();
        list.stream().forEach(item->{
            rst.add((Integer)item);
        });
        return rst;
    }

    /**
     * 根据课程id删除
     *
     * @param ids
     */
    @Override
    public void deleteByCourse(List<Serializable> ids) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.in("fk_course_id", ids);
        getBaseMapper().delete(wrapper);
    }

    /**
     * 根据用户id禁用
     *
     * @param ids
     */
    @Override
    public void deleteByUser(List<Serializable> ids) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.in("fk_user_id", ids);
        getBaseMapper().delete(wrapper);
    }
}
